import protocal.credential
from protocal.didcodec import DIDCodec

vcsample = '''{
    "@context": [
        "https://www.w3.org/2018/credentials/v1",
        "https://www.w3.org/2018/credentials/examples/v1"
    ],
    "id": "http://example.edu/credentials/1872",
    "type": ["VerifiableCredential", "AlumniCredential"],
    "issuer": "https://example.edu/issuers/565049",
    "issuanceDate": "2010-01-01T19:23:24Z",
    "credentialSubject": {
        "id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
        "alumniOf": {
            "id": "did:example:c276e12ec21ebfeb1f712ebc6f1",
            "name": [{
                "value": "Example University",
                "lang": "en"
            }, {
                "value": "Exemple d'Université",
                "lang": "fr"
            }]
        }
    },
    "proof": {
        "type": "RsaSignature2018",
        "created": "2017-06-18T21:19:10Z",
        "proofPurpose": "assertionMethod",
        "verificationMethod": "https://example.edu/issuers/565049#key-1",
        "jws": "eyJhbGciOiJSUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19"
    }
}'''

from protocal.credential import Credential
vc = DIDCodec.from_json(vcsample,Credential)
print("VCOBJECT->",vc)
vccbor = DIDCodec.to_cbor(vc)
print("CBOR->",vccbor)

vcjsonld = DIDCodec.to_jsonld(vc,context=protocal.credential.vc_context)
print("JSONLD ->",vcjsonld)



timestr = "2020-04-22T10:37:22Z"
tm = DIDCodec.from_timestr(timestr)
print("TIME->",tm)
print(DIDCodec.to_timestr(tm))